/**
 * 
 * 
 */

#include "eccodes.h"

int sfx_values_check()
{
    int err = 0;

    const char *infile = "d:/sfxData/ecmwf/eccodes_test_data/reduced_gaussian_model_level.grib1";

    FILE *f = fopen(infile, "rb");
    if (!f)
    {
        perror(infile);
        exit(1);
    }

    codes_context *c = codes_context_get_default();
    codes_handle *h = codes_handle_new_from_file(c, f, PRODUCT_GRIB, &err);
    if (!h)
    {
        fprintf(stderr, "unable to create handle from file %s\n", infile);
        fclose(f);
        exit(err);
    }

    codes_values values[2];

    values[0].type = CODES_TYPE_LONG;
    values[0].name = "centre";
    values[0].long_value = 98;

    values[1].type = CODES_TYPE_LONG;
    values[1].name = "level";
    values[1].long_value = 2;

    // CODES_VALUE_DIFFERENT -> value is different
    char *name = NULL;
    int nvalues = 2;
    err = codes_values_check(h, values, nvalues);
    if (err)
    {
        for (int i = 0; i < nvalues; i++)
        {
            if (values[i].error == err)
                name = (char *)values[i].name;
        }
        fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err));
    }

    values[1].name = "levelll";
    err = codes_values_check(h, values, nvalues);
    if (err)
    {
        for (int i = 0; i < nvalues; i++)
        {
            if (values[i].error == err)
                name = (char *)values[i].name;
        }
        fprintf(stderr, "Error: \"%s\" %s\n", name, codes_get_error_message(err));
    }

    fclose(f);
    return 0;
}
